package com.jrfid.smartcabinet.demo.ui.inventory

import androidx.lifecycle.ViewModelProvider
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.*
import com.jrfid.smartcabinet.demo.R
import com.jrfid.smartcabinet.demo.base.BaseFragment
import com.jrfid.smartcabinet.demo.databinding.InventoryFragmentBinding

class InventoryFragment : BaseFragment<InventoryFragmentBinding, InventoryViewModel>(InventoryViewModel::class.java) {

    companion object {
        fun newInstance() = InventoryFragment()
    }

    override fun getLayoutId(): Int = R.layout.inventory_fragment

    override fun setData() {
//        val height = ScreenUtils.getScreenHeight()
//        val appbarHeight = BarUtils.getActionBarHeight()
//        val dp120 = SizeUtils.dp2px(120f)
//        val minHeight = height - appbarHeight - dp120

//        getDataBinding()?.recyclerView?.addOnScrollListener(object : RecyclerView.OnScrollListener() {
//            override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
//                super.onScrolled(recyclerView, dx, dy)
//                val manager = recyclerView.layoutManager
//                if (manager is GridLayoutManager) {
//                    val spanCount = manager.spanCount
//                    val itemCount = manager.itemCount
//                    val position = manager.findLastVisibleItemPosition()
//                    LogUtils.dTag(TAG, "最后一个显示：${position}")
//                    val view = manager.findViewByPosition(position)
//                    LogUtils.dTag(
//                        TAG,
//                        "最后一个${position}：x = ${view?.x},y = ${view?.y},top = ${view?.top},bottom = ${view?.bottom},height = ${view?.height},screen = ${height},bar = $appbarHeight"
//                    )
//                    if (view != null) {
//                        if (position == itemCount && position > spanCount) {
//                            val m = position % spanCount
//                            val n = if (m == 0) spanCount else m
//                            val view2 = manager.findViewByPosition(position - 1)
//                            view2?.let {
//                                val p = if (it.bottom >= minHeight) 1 - (it.bottom - minHeight) * 1f / (dp120 + it.height) else 1f
//                                for (i in 1..n) {
//                                    val v = manager.findViewByPosition(position - i)
//                                    v?.alpha = p
//                                }
//                            }
//                        } else {
//                            val m = position % spanCount
//                            val p = if (view.bottom >= minHeight) 1 - (view.bottom - minHeight) * 1f / (dp120 + view.height) else 1f
//                            for (i in 0..(m + spanCount)) {
//                                val v = manager.findViewByPosition(position - i)
//                                v?.alpha = p
//                            }
//                            val view2 = manager.findViewByPosition(position - m - 1)
//                            view2?.let {
//                                val p2 = if (it.bottom >= minHeight) 1 - (it.bottom - minHeight) * 1f / (dp120 + it.height) else 1f
//                                for (i in (m + 1)..(m + spanCount)) {
//                                    val v = manager.findViewByPosition(position - i)
//                                    v?.alpha = p
//                                }
//                            }
//
//                        }
//                    }
//
//
////                    if (view != null) {
////                        val p = if (view.bottom >= minHeight) 1 - (view.bottom - minHeight) * 1f / (dp90 + view.height) else 1f
////                        LogUtils.dTag(TAG, "当前百分比：${p}")
////                        view.alpha = p
////                        view2?.alpha = p
////                    }
////                    if (view3 != null) {
////                        val p = if (view3.bottom >= minHeight) 1 - (view3.bottom - minHeight) * 1f / (dp90 + view3.height) else 1f
////                        LogUtils.dTag(TAG, "当前百分比：${p}")
////                        view3.alpha = p
////                        view4?.alpha = p
////                    }
//                }
//            }
//        })
    }

}